import { createRouter, createWebHistory } from 'vue-router'
import FormRender from '../formDesigner/formRender/FormRender.vue'
import FormRenderDemo from '../views/FormRenderDemo/FormRenderDemo.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    meta: {
      title: '首页'
    }
  },
  // {
  //   path: '/form-generator',
  //   name: 'form-generator',
  //   component: FormGenerator,
  //   meta: {
  //     title: '表单生成器'
  //   }
  // },
  {
    path: '/form-render',
    name: 'form-render',
    component: FormRender,
    meta: {
      title: '表单渲染器'
    }
  },
  {
    path: '/form-render-demo',
    name: 'form-render-demo',
    component: FormRenderDemo,
    meta: {
      title: '表单演示'
    }
  },
  {
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - Fly Code Form`
  }
  
  console.log(`路由跳转: ${from.path} -> ${to.path}`)
  next()
})

export default router